// components/drinklist/drinklist.js
Component({
    /**
     * 页面的初始数据
     */
    properties: {
        catId: {
            type: Number,
            value: 0
        },
        // 饮品类别
        drinkType: {
            type: JSON,
            value: {}
        }
    },
    data: {
        id: 0,
        list_drinks: [],
        drinks: []
    },
    lifetimes: {
        attached() {
            // console.log(this.properties)

            this.setData({
                id: this.properties.catId
            })
            if (this.data.id === 0) {
                wx.request({
                    url: 'http://127.0.0.1:3000/drinks/top',
                    method: 'GET',
                    Type: "json",
                    success: (res) => {
                        //console.log(res.data)
                        this.setData({
                            drinks: res.data
                        })
                        console.log('人气Top',this.data.drinks)
                    }
                })
            } else {
                wx.request({
                    url: 'http://127.0.0.1:3000/drink/' + this.data.id,
                    method: 'GET',
                    Type: "json",
                    success: (res) => {
                        //console.log(res.data)
                        this.setData({
                            drinks: res.data
                        })
                        console.log('sss',this.data.drinks)
                    }
                })
            }
        }
    }
})